package com.ruoyi.environment.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;;
import com.ruoyi.environment.domain.OpmEnvSoldTest;
import com.ruoyi.environment.mapper.OpmEnvSoldTestMapper;
import com.ruoyi.environment.service.IOpmEnvSoldTestService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 固废采集Service业务层处理
 *
 * @author cjie
 * @date 2021-07-23
 */
@Service
public class OpmEnvSoldTestServiceImpl extends LinkFileServiceImpl implements IOpmEnvSoldTestService {
    @Autowired
    private OpmEnvSoldTestMapper opmEnvSoldTestMapper;

    /**
     * 查询固废采集
     *
     * @param id 固废采集ID
     * @return 固废采集
     */
    @Override
    public OpmEnvSoldTest selectOpmEnvSoldTestById(Long id) {
        OpmEnvSoldTest result = opmEnvSoldTestMapper.selectOpmEnvSoldTestById(id);
        result.setFileList(getFileList(id.toString()));
        return result;
    }

    /**
     * 查询固废采集列表
     *
     * @param opmEnvSoldTest 固废采集
     * @return 固废采集
     */
    @Override
    public List<OpmEnvSoldTest> selectOpmEnvSoldTestList(OpmEnvSoldTest opmEnvSoldTest) {
        return opmEnvSoldTestMapper.selectOpmEnvSoldTestList(opmEnvSoldTest);
    }

    /**
     * 新增固废采集
     *
     * @param opmEnvSoldTest 固废采集
     * @return 结果
     */
    @Override
    public int insertOpmEnvSoldTest(OpmEnvSoldTest opmEnvSoldTest) {
        opmEnvSoldTest.setId(IdUtil.getSnowflake(0, 0).nextId());
        opmEnvSoldTest.setCreateTime(DateUtils.getNowDate());
        opmEnvSoldTest.setCreateBy(SecurityUtils.getUsername());
        linkFile(opmEnvSoldTest.getFileIdList(), opmEnvSoldTest.getId().toString());
        return opmEnvSoldTestMapper.insertOpmEnvSoldTest(opmEnvSoldTest);
    }

    /**
     * 修改固废采集
     *
     * @param opmEnvSoldTest 固废采集
     * @return 结果
     */
    @Override
    public int updateOpmEnvSoldTest(OpmEnvSoldTest opmEnvSoldTest) {
        opmEnvSoldTest.setUpdateTime(DateUtils.getNowDate());
        opmEnvSoldTest.setUpdateBy(SecurityUtils.getUsername());
        linkFile(opmEnvSoldTest.getFileIdList(),Long.toString(opmEnvSoldTest.getId()));
        return opmEnvSoldTestMapper.updateOpmEnvSoldTest(opmEnvSoldTest);
    }

    /**
     * 批量删除固废采集
     *
     * @param ids 需要删除的固废采集ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvSoldTestByIds(Long[] ids) {
        String[] res = new String[ids.length];
        for(int i=0;i<ids.length;i++){
            res[i] = String.valueOf(ids[i]);
        }
        deleteLinkFile(res);
        return opmEnvSoldTestMapper.deleteOpmEnvSoldTestByIds(ids);
    }

    /**
     * 删除固废采集信息
     *
     * @param id 固废采集ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvSoldTestById(Long id) {
        return opmEnvSoldTestMapper.deleteOpmEnvSoldTestById(id);
    }
}
